import { ListNode } from "./listNode.js";

class Solution {
    static removeElements(head, val) {
        let dummyNode = new ListNode(null)
        dummyNode.next = head

        let pre = dummyNode
        while(pre.next != null) {
            if (pre.next.val == val) {
                pre.next = pre.next.next
            }else {
                pre = pre.next
            }
        }
        return dummyNode.next
    }

    static removeElementsByRecursion(head, val) {
        if (head == null) {
            return null
        }
        if (head.val === val) {
            return Solution.removeElementsByRecursion(head.next, val)
        }else {
            head.next = Solution.removeElementsByRecursion(head.next, val)
            return head
        }
    }
}

export { Solution }